<?php
namespace app\jiajiao\controller;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/29
 * Time: 17:25
 * 该类中方法列表说明：
 * 老师数据展示页面 index()
 * 学员数据展示页面 students()
 * 老师认证信息展示 techrenzheng()
 * 老师认证搜索    searchrenzheng()
 * 学员数据信息搜索  searchstudents()
 * 搜索老师信息   searchteachs()
 * 通过认证      isrenzheng()
 * 每个老师的上课的费用页面  priceset()
 *设置价格 setprice()
 * 设置状态 setstatus()
 *获取评论内容  getpinglun()
 * 删除评论信息 pinlundel()
 * 搜索评论内容  pinlunsearch()
 * 配置客服电话页面  config()
 * 配置客服电话   setconfig()
 *获取预约信息 getyuyue()
 * 开始预约  yuyue()
 *删除预约 deleteyuyue()
 * 预约搜索 yuyuesearchs()
 * 设置轮播图片  lunbo()
 * 添加轮播图片 addImages()
 *删除学生 deletestu()
 *删除老师的信息  deleteteach()
 * 添加老师页面 teachadd()
 * 修改学生的数据 editstu()
 * 学生信息修改页面 stuedit()
 */
use app\jiajiao\model\TeacherModel;
use cmf\controller\AdminBaseController;
use app\admin\model;
use think\Db;
class TechAdminController  extends AdminBaseController
{
    private $tech;
    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
        $this->tech = new TeacherModel();
    }
    public function test(){
            echo 'sss';
             return $this->fetch('index');
       }
    /***
     * 老师数据展示页面
     */
    public function index(){
        // $result = $this->tech->paginate(10);
         $result = $this->tech->alias('t')->join('edu_juzhong j','t.juzhong=j.type')->field('t.id,t.username,t.xingming,t.nianling,t.headimage,t.dianhua,t.xingbie,t.address,t.hangdang,j.name as juzhong,t.isrenzheng,t.dottime,t.price')->where('deltime','0')->order('id desc')->paginate(8);
         
         $this->assign('res',$result);//老师的数据信息
         $this->assign('page',$result->render());
         $res = Db::name('juzhong')->select();
         
         $this->assign('juzhong',$res);
         return $this->fetch();
    }
    /***
     * 学员数据展示页面
     */
    public function students(){
        $res = Db::name('juzhong')->select();
        $result = Db::name('userinfo')->alias('t')->join('edu_juzhong j','t.juzhong=j.type')->field('t.id,t.username,t.xingming,t.nianling,t.headimage,t.dianhua,t.xingbie,t.address,t.hangdang,j.name as juzhong,t.dottime,t.status')->where('deltime','0')->order('id desc')->paginate(8);
        $this->assign('res',$result);//学员的数据信息
        $this->assign('page',$result->render());
        $this->assign('juzhong',$res);
        return $this->fetch();
    }

    /**
     * 老师认证信息展示
     */
    public function techrenzheng(){
        $res = Db::name('juzhong')->select();
        $result = $this->tech->alias('t')->join('edu_juzhong j','t.juzhong=j.type')->field('t.id,t.hangdang,t.danwei,t.images,t.liupai,t.rongyu,t.zhengshu,t.yuanxiao,t.jianjie,j.name as juzhong,t.shicong,t.username,t.renzhengtime,t.isrenzheng')->where('deltime','0')->order('id desc')->paginate(8);
        //print_r($result);exit;
        /*$result2 = json_decode(json_encode($result));
        $result1 = $result2->data;
        foreach($result1 as $k => $v){
            $result1[$k]->images = json_decode(stripslashes($v->images));
            $result1[$k]->zhengshu = json_decode(stripslashes($v->zhengshu));
        }*/
        //print_r($result1);exit;
        $this->assign('res',$result);//老师的数据信息
        $this->assign('page',$result->render());
        $this->assign('juzhong',$res);
        return $this->fetch('rezheng');
    }

    /**
     * 老师认证搜索
     */
    public function searchrenzheng(){
        $sql=$this->tech->alias('t')->join('edu_juzhong j','t.juzhong=j.type');
        $juzhong = input('juzhong');
        if($juzhong!='all'){
            $sql = $sql->where('j.id',$juzhong);
        }
        $renzheng = input('rezheng');
        if($renzheng!='all'){
            $sql = $sql->where('t.isrenzheng',$renzheng);
        }
        $start_time = input('start_time');//开始时间
        $end_time = input('end_time');//结束时间
        if($start_time!=null&&$end_time!=null){
            $sql = $sql->where('renzhengtime','>=',strtotime($start_time))->where('renzhengtime','<=',strtotime($end_time));
        }else if($start_time!=null&&$end_time==null){
            $this->error('请选择结束时间');
        }else if($start_time==null&&$end_time!=null){
            $this->error('请选择开始时间');
        }
        $keyword = input('keyword');//关键词
        if($keyword!=null){
            $sql = $sql->where('t.hangdang|t.liupai|j.name|t.username|t.xingming','like','%'.$keyword.'%');
        }
        $result = $sql->field('t.id,t.hangdang,t.danwei,t.images,t.liupai,t.rongyu,t.zhengshu,t.yuanxiao,t.jianjie,j.name as juzhong,t.shicong,t.username,t.renzhengtime,t.isrenzheng')->where('deltime','0')->order('id desc')->paginate(8);

        $res = Db::name('juzhong')->select();
        $this->assign('res',$result);//老师的数据信息
        $this->assign('page',$result->render());
        $this->assign('juzhong',$res);
        return $this->fetch('rezheng');
    }

    /**
     * 学员数据信息搜索
     */
    public function searchstudents(){
        $sql= Db::name('userinfo')->alias('t')->join('edu_juzhong j','t.juzhong=j.type');
        $juzhong = input('juzhong');
        if($juzhong!='all'){
            $sql = $sql->where('j.id',$juzhong);
        }
        $start_time = input('start_time');//开始时间
        $end_time = input('end_time');//结束时间
        if($start_time!=null&&$end_time!=null){
            $sql = $sql->where('dottime','>=',strtotime($start_time))->where('dottime','<=',strtotime($end_time));
        }else if($start_time!=null&&$end_time==null){
            $this->error('请选择结束时间');
        }else if($start_time==null&&$end_time!=null){
            $this->error('请选择开始时间');
        }
        $keyword = input('keyword');//关键词
        if($keyword!=null){
            $sql = $sql->where('t.hangdang|t.liupai|j.name|t.username|t.xingming','like','%'.$keyword.'%');
        }

        $result = $sql->where('deltime','0')->field('t.id,t.username,t.xingming,t.nianling,t.headimage,t.dianhua,t.xingbie,t.address,t.hangdang,j.name as juzhong,t.status,t.dottime')->where('deltime','0')->order('id desc')->paginate(8);
        $res = Db::name('juzhong')->select();
        $this->assign('res',$result);//老师的数据信息
        $this->assign('page',$result->render());
        $this->assign('juzhong',$res);
        return $this->fetch('students');
    }

    /**
     * 搜索老师信息
     */
    public function searchteachs(){
        $sql=$this->tech->alias('t')->join('edu_juzhong j','t.juzhong=j.type');
        $juzhong = input('juzhong');
        if($juzhong!='all'){
            $sql = $sql->where('j.id',$juzhong);
        }
        $renzheng = input('rezheng');
        if($renzheng!='all'){
            $sql = $sql->where('t.isrenzheng',$renzheng);
        }
        $start_time = input('start_time');//开始时间
        $end_time = input('end_time');//结束时间
        if($start_time!=null&&$end_time!=null){
            $sql = $sql->where('dottime','>=',strtotime($start_time))->where('dottime','<=',strtotime($end_time));
        }else if($start_time!=null&&$end_time==null){
            $this->error('请选择结束时间');
        }else if($start_time==null&&$end_time!=null){
            $this->error('请选择开始时间');
        }
        $keyword = input('keyword');//关键词
        if($keyword!=null){
            $sql = $sql->where('t.hangdang|t.liupai|j.name|t.username|t.xingming','like','%'.$keyword.'%');
        }
        $result = $sql->field('t.id,t.username,t.xingming,t.nianling,t.headimage,t.dianhua,t.xingbie,t.address,t.hangdang,j.name as juzhong,t.isrenzheng,t.dottime,t.price')->where('deltime','0')->order('id desc')->paginate(8);

        $res = Db::name('juzhong')->select();
        $this->assign('res',$result);//老师的数据信息
        $this->assign('page',$result->render());
        $this->assign('juzhong',$res);
        return $this->fetch('index');
    }

    /**
     * 通过认证
     */
    public function isrenzheng(){
        $id = input('id');
        $result=$this->tech->where('id',$id)->update(array('isrenzheng'=>1,'renzhengtime'=>time()));//认证通过
        if($result>0){
            $this->success('认证通过');
        }else{
            $this->error('认证失败');
        }
    }

    /**
     * 每个老师的上课的费用页面
     */
    public function priceset(){
        $id = input('id');
        $result = Db::name('teacher')->where('id',$id)->find();
      //  print_r($result);exit;
        if(empty($result['headimage'])){
          $this->assign('headimg2','');
            $this->assign('headimg','__TMPL__/public/assets/images/default-thumbnail.png');
        }else{
            $this->assign('headimg','http://'.$_SERVER['HTTP_HOST'].'/upload/'.$result['headimage']);
            $this->assign('headimg2',$result['headimage']);
        }
        $this->assign('teachers',$result);
        $resjuzhong = Db::name('juzhong')->field('name,type')->select();
        $this->assign('juzhong',$resjuzhong);
        return $this->fetch('editteach');
    }

    /**
     * 设置价格
     */
    public function setprice(){
        $id = input('id');
        $price = input('price');
        $username = input('username');
        $headimg = input('headimg.thumbnail');
        $password = input('password');
        $pinglun= input('pinglun');
        $preg = '^[1-9]d*$^';
        if(preg_match($preg,$price)){
            $this->error('输入的价格必须为正整数');
        }
        $data['price'] = $price;
        $data['username'] = $username;
        if(!empty($password)){
            $data['password'] = md5($password);
        }

        $data['headimage'] = $headimg;
        $xingming = input('xingming');
        $age = input('age');
        $address = input('address');
        $hangdang = input('hangdang');
        $juzhong = input('juzhong');
        $sex = input('sex');
        $phone = input('phone');
        $data['address'] = $address;
        $data['hangdang'] = $hangdang;
        $data['nianling'] = $age;
        $data['xingbie'] = $sex;
        $data['juzhong'] = $juzhong;
        $data['xingming'] = $xingming;
        $data['dianhua'] = $phone;
        $data['dottime'] = time();

        $result = $this->tech->where('id',$id)->update($data);
        $datas['techid'] = $id;
        $datas['studentid'] = 1074;
        $datas['content'] = $pinglun;
        $datas['dottime'] = time();
        $ress = Db::name('pinglun')->where('techid',$id)->find();
        if(count($ress)>0){
            $res = Db::name('pinglun')->where('techid',$id)->update($datas);
        }else{
            $res = Db::name('pinglun')->insert($datas);
        }

        if($result>0){
           $this->success('提交成功');
        }else{
           $this->error('提交失败');
        }
    }

    /**
     * 设置状态
     */
    public function setstatus(){
        $id = input('id');
        $result = Db::name('userinfo')->where('id',$id)->find();
        $data['status'] = !$result['status'];
        $res= Db::name('userinfo')->where('id',$id)->update($data);
        if($res>0){
           $this->success('设置成功');
        }else{
            $this->error('设置失败');
        }
    }

    /**
     * 获取评论内容
     */
    public function getpinglun(){
        $techid = input('id');
        $result = $this->tech->alias('t')->join('edu_pinglun p','t.id=p.techid')->join('edu_userinfo u','u.id=p.studentid')->where('t.id',$techid)->where('p.deltime','EQ','')->field('t.xingming ,u.xingming as stuname,p.content,p.dottime,p.id')->select();
        $this->assign('res',$result);
        $this->assign('techid',$techid);
        return $this->fetch('punlun');
    }

    /**
     *删除评论信息
     */
    public function pinlundel(){
        $id = input('id');
        $result = Db::name('pinglun')->where('id',$id)->update(array('deltime'=>time()));
        if($result>0){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 搜索评论内容
     */
    public function pinlunsearch(){
        $techid = input('id');
        $sql = $this->tech->alias('t')->join('edu_pinglun p','t.id=p.techid')->join('edu_userinfo u','u.id=p.studentid')->where('t.id',$techid)->where('p.deltime','EQ','');
        $start_time = input('start_time');//开始时间
        $end_time = input('end_time');//结束时间
        if($start_time!=null&&$end_time!=null){
            $sql = $sql->where('p.dottime','>=',strtotime($start_time))->where('p.dottime','<=',strtotime($end_time));
        }else if($start_time!=null&&$end_time==null){
            $this->error('请选择结束时间');
        }else if($start_time==null&&$end_time!=null){
            $this->error('请选择开始时间');
        }
        $keyword = input('keyword');//关键词
        if($keyword!=null){
            $sql = $sql->where('u.xingming','like','%'.$keyword.'%');
        }
        $result = $sql->field('t.xingming ,u.xingming as stuname,p.content,p.dottime,p.id')->select();
        $this->assign('res',$result);
        $this->assign('techid',$techid);
        return $this->fetch('punlun');
    }

    /**
 * 配置客服电话页面
 */
    public function config(){

            $result = Db::name('config')->find();

            if(count($result)>0){
                $this->assign('config',$result);
            }else{
                $this->assign('config',array('id'=>'','phone'=>''));
            }

        return $this->fetch('config');
    }
    /**
     * 配置客服电话
     */
    public function setconfig(){
        $id = $this->request->param('id');
        $phone = $this->request->param('phone');
        if(!empty($id)){//已经配置过
           // $result = Db::name('config')->where('id',$id)->count();
           /// if($result>0){
                $result = Db::name('config')->where('id',$id)->update(array('phone'=>$phone,'dottime'=>time()));
                if($result>0){
                    $this->success('配置成功');
                }else{
                    $this->error('配置失败');
                }
           // }
        }else{//第一次配置
            $result = Db::name('config')->insert(array('phone'=>$phone,'dottime'=>time()));
            if($result>0){
                $this->success('配置成功');
            }else{
                $this->error('配置失败');
            }
        }
    }

    /**
     *获取预约信息
     */
    public function getyuyue(){
        /*$result = Db::name('yuyue')->alias('y')->join('edu_teacher e','y.techid =e.id')->join('edu_userinfo u','u.id = y.userid')
            ->where('y.deltime','EQ','0')
            ->field('e.xingming as techname,e.dianhua as techphone,y.techjuzhong ,y.techhangdang,y.techprice,u.xingming as yuyuename,u.dianhua as yuyuephone,y.dottime')
            ->paginate(8);*/
        $result = Db::name('yuyue')->alias('y')->join('edu_teacher e','y.techid =e.id')
            ->where('y.deltime','EQ','0')
            ->field('e.xingming as techname,e.dianhua as techphone,e.juzhong as techjuzhong,e.hangdang,y.techprice, y.stuname,y.userphone,y.dottime,y.status,y.id')
            ->paginate(8);
        //echo Db::name('userinfo')->getLastSql();
       $this->assign('res',$result);
        $this->assign('page',$result->render());
        return $this->fetch('yuyue');
    }

    /**
     * 开始预约
     */
    public function yuyue(){
        $id = input('id');
        $result = Db::name('yuyue')->where('id',$id)->find();
        $status = !$result['status'];
        $result = Db::name('yuyue')->where('id',$id)->update(array('status'=>1));
        if($result>0){
            $this->success('设置成功');
        }else{
            $this->error('设置失败');
        }
    }

    /**
     * 删除预约
     */
    public function deleteyuyue(){
        $id = input('id');
        $result = Db::name('yuyue')->where('id',$id)->update(array('deltime'=>time()));
        if($result>0){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 预约搜索
     */
    public function yuyuesearchs(){
        $sql=Db::name('yuyue')->alias('y')->join('edu_teacher e','y.techid =e.id')
            ->where('y.deltime','EQ','0');
        $start_time = input('start_time');//开始时间
        $end_time = input('end_time');//结束时间
        if($start_time!=null&&$end_time!=null){
            $sql = $sql->where('p.dottime','>=',strtotime($start_time))->where('p.dottime','<=',strtotime($end_time));
        }else if($start_time!=null&&$end_time==null){
            $this->error('请选择结束时间');
        }else if($start_time==null&&$end_time!=null){
            $this->error('请选择开始时间');
        }
        $keyword = input('keyword');//关键词
        if($keyword!=null){
            $sql = $sql->where('y.stuname|e.xingming|y.techjuzhong|y.hangdang','like','%'.$keyword.'%');
        }
        $result = $sql->field('e.xingming as techname,e.dianhua as techphone,e.juzhong as techjuzhong,e.hangdang,y.techprice, y.stuname,y.stuphone,y.dottime')
            ->paginate(8);
        //echo Db::name('userinfo')->getLastSql();
        $this->assign('res',$result);
        $this->assign('page',$result->render());
        return $this->fetch('yuyue');
    }

    /**
     * 设置轮播图片
     */
    public function lunbo(){
        $result = Db::name('lunbo')->where('id',1)->find();
        $images = json_decode(stripslashes($result['images']));
        $this->assign('images',$images);
        return $this->fetch('lunbo');
    }
    /**
     * 添加轮播图片
     */
    public function addImages(){
        $fileds = $this->request->param();

        $data['images'] = addslashes(json_encode($fileds['imgs']));//$imgs = stripslashes($imgs);//addslashes(json_encode($data['imgs']));  $imgs = json_decode($imgs);
        $data['dottime'] = time();
        $res = Db::name('lunbo')->find();
        if(empty($res)){
            $result = Db::name('lunbo')->insert($data);
        }else{
            $result = Db::name('lunbo')->where('id',$res['id'])->update($data);
        }
        if($result>0){
            $this->success('提交成功');
        }else{
            $this->error('提交失败');
        }
    }

    /**
     * 设置老师
     */
    public function setinfo(){

    }
    /**
     * 删除学生
     */
    public function deletestu(){
        $id = $this->request->param('id');
        $ids = $this->request->param('ids/a');
        $deltime = time();
        if(!empty($id)){
            $result = Db::name('userinfo')->where('id',$id)->update(array('deltime'=>$deltime));//删除数据
        }else if(!empty($ids)){
            $result = Db::name('userinfo')->where(array('id'=>array('in',$ids)))->update(array('deltime'=>$deltime));
        }else{
            $this->error('请选择删除选项！');
        }
        if($result >0){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 删除老师的信息
     */
    public function deleteteach(){
        $id = $this->request->param('id');
        $ids = $this->request->param('ids/a');
        $deltime = time();
        if(!empty($id)){
            $result = Db::name('teacher')->where('id',$id)->update(array('deltime'=>$deltime));//删除数据
        }else if(!empty($ids)){
            $result = Db::name('teacher')->where(array('id'=>array('in',$ids)))->update(array('deltime'=>$deltime));
        }else{
            $this->error('请选择删除选项！');
        }
        if($result >0){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 添加老师页面
     */
    public function teachadd(){
        $resjuzhong = Db::name('juzhong')->field('name,type')->select();
        $this->assign('juzhong',$resjuzhong);
        return $this->fetch('addteacher');
    }

    /**
     * 老师信息添加
     */
    public function addteachadd(){
        $username = input('username');
        $password = input('password');
        $repassword = input('repassword');
        $xingming = input('xingming');
        $age = input('age');
        $address = input('address');
        $hangdang = input('hangdang');
        $juzhong = input('juzhong');
        $sex = input('sex');
        $phone = input('phone');
        $touxiang = input('touxiang.thumbnail');
        $str ='^[_0-9a-zA-Z]{n}$^';
        $result = Db::name('teacher')->where('username',$username)->find();
        if(preg_match($str,$username)){
            $this->error('用户名不符合规则');
        }else if($result>0){
            $this->error('用户名已经存在');
        }else if($password !=$repassword){
            $this->error('密码输入不一致');
        }
        $datas['username'] = $username;
        $datas['password'] = md5($password);
        $datas['headimage'] = $touxiang;
        $datas['address'] = $address;
        $datas['hangdang'] = $hangdang;
        $datas['nianling'] = $age;
        $datas['xingbie'] = $sex;
        $datas['juzhong'] = $juzhong;
        $datas['xingming'] = $xingming;
        $datas['dianhua'] = $phone;
        $datas['dottime'] = time();
        $results = Db::name('teacher')->insert($datas);
        if($results>0){
            $this->success('增加成功');
        }else{
            $this->success('增加失败');
        }
    }

    /**
     * 学生添加信息页面
     */
    public function stuadd(){
        $resjuzhong = Db::name('juzhong')->field('name,type')->select();
        $this->assign('juzhong',$resjuzhong);
        return $this->fetch('addstu');
    }
    /**
     * 增加学生的信息
     */
    public function addstu(){
        $username = input('username');
        $password = input('password');
        $repassword = input('repassword');
        $xingming = input('xingming');
        $age = input('age');
        $address = input('address');
        $hangdang = input('hangdang');
        $juzhong = input('juzhong');
        $sex = input('sex');
        $phone = input('phone');
        $touxiang = input('touxiang.thumbnail');
        $str ='^[_0-9a-zA-Z]{n}$^';
        $result = Db::name('userinfo')->where('username',$username)->find();
        if(preg_match($str,$username)){
            $this->error('用户名不符合规则');
        }else if($result>0){
            $this->error('用户名已经存在');
        }else if($password !=$repassword){
            $this->error('密码输入不一致');
        }
        $datas['username'] = $username;
        $datas['password'] = md5($password);
        $datas['headimage'] = $touxiang;
        $datas['address'] = $address;
        $datas['hangdang'] = $hangdang;
        $datas['nianling'] = $age;
        $datas['xingbie'] = $sex;
        $datas['juzhong'] = $juzhong;
        $datas['xingming'] = $xingming;
        $datas['dianhua'] = $phone;
        $datas['dottime'] = time();
        $results = Db::name('userinfo')->insert($datas);
        if($results>0){
            $this->success('增加成功');
        }else{
            $this->success('增加失败');
        }
    }

    /**
     *学生修改页面
     */
    public function stuedit(){
        $id = input('id');
        $result = Db::name('userinfo')->where('id',$id)->find();
        $headimage = $result['headimage'];
        $headimage2 =($headimage==''?'__TMPL__/public/assets/images/default-thumbnail.png':'http://'.$_SERVER['HTTP_HOST'].'/'.$headimage);
        $this->assign('headimage',$headimage);
        $this->assign('headimage2',$headimage2);
        $resjuzhong = Db::name('juzhong')->field('name,type')->select();
        $this->assign('juzhong',$resjuzhong);
        $this->assign('res',$result);
        return $this->fetch('editstu');
    }

    /**
     * 修改学生的数据
     */
    public function editstu(){
        $id = input('id');
        $password = input('password');

        $xingming = input('xingming');
        $age = input('age');
        $address = input('address');
        $hangdang = input('hangdang');
        $juzhong = input('juzhong');
        $sex = input('sex');
        $phone = input('phone');
        $touxiang = input('touxiang.thumbnail');
        if(!empty($password)){
            $datas['password'] = md5($password);
        }
        $datas['headimage'] = $touxiang;
        $datas['address'] = $address;
        $datas['hangdang'] = $hangdang;
        $datas['nianling'] = $age;
        $datas['xingbie'] = $sex;
        $datas['juzhong'] = $juzhong;
        $datas['xingming'] = $xingming;
        $datas['dianhua'] = $phone;
        $datas['dottime'] = time();
        $results = Db::name('userinfo')->where('id',$id)->update($datas);
        if($results>0){
            $this->success('修改成功');
        }else{
            $this->success('修改失败');
        }
    }

    /**
     * 认证信息
     *
     */
    public function rerenzheng(){
        $id = input('id');
        $this->assign('id',$id);
        return $this->fetch('rerengzheng');
    }

    /**
     * 添加认证信息
     * addslashes(json_encode($data['imgs']))
     */
    public function addrengzheng(){
        $id = input('id');
        $danwei  = input('danwei');
        $rongyu  = input('rongyu');
        $yuanxiao  = input('yuanxiao');
        $jianjie  = input('jianjie');
        $shicong  = input('shicong');
        $coverimg  = $this->request->param('zhaopian/a');
       // print_r($coverimg);exit;
        $imgs  = $this->request->param('imgs/a');//post提交的数组数据，需要用/a来接收
        $data2 = array();
        if(!empty($danwei)){
            $data2['danwei'] = $danwei;
        }
        if(!empty($rongyu)){
            $data2['rongyu'] = $rongyu;
        }
        if(!empty($yuanxiao)){
            $data2['yuanxiao'] = $yuanxiao;
        }
        if(!empty($jianjie)){
            $data2['jianjie'] = $jianjie;
        }
        if(!empty($shicong)){
            $data2['shicong'] = $shicong;
        }
       // print_r(addslashes(json_encode($coverimg)));exit;

        if(!empty($coverimg)){
            $data2['images'] =addslashes(json_encode($coverimg));
        }
        if(!empty($imgs)){
            $data2['zhengshu'] = addslashes(json_encode($imgs));
        }
       // print_r($data2);exit;
        $result = Db::name('teacher')->where('id',$id)->update($data2);
     //   echo Db::name('teacher')->getLastSql();exit;
        if($result>0){
            $this->success('提交成功');
        }else{
            $this->error('提交失败');
        }
    }

    /**
     * 留言展示页面
     */
    public function liuyan(){
        $result = Db::name('zixun')->alias('z')->join('edu_userinfo u','z.userid = u.id')->where('z.deltime','0')->order('z.id desc')->field('z.id,u.xingming as name,z.content,z.recontent,z.dottime,z.redottime')->paginate(8);
        $page = $result->render();
        $this->assign('res',$result);
        $this->assign('page',$page);
        return $this->fetch('liuyan');
    }

    /**
     * 回复留言
     */
    public function huifuliuyan(){
        $id = input('id');
        $result = Db::name('zixun')->alias('z')->join('edu_userinfo u','z.userid = u.id')->where('z.deltime','0')->field('z.id,u.xingming as name,z.content,z.recontent,z.dottime,z.redottime')->where('z.id',$id)->find();
        $this->assign('res',$result);
        return $this->fetch('huifuliuyan');
    }

    /**
     * 对留言进行留言
     */
    public function reliuyan(){
        $id = input('id');
        $recontent = input('recontent');
        $data['recontent'] = $recontent;
        $data['redottime'] = time();
        $result = Db::name('zixun')->where('id',$id)->update($data);
        if($result>0){
            $this->success('提交成功');
        }else{
            $this->success('提交失败');
        }
    }

    /**
     * 删除留言
     */
    public function deleteliuyan(){
        $id = input('id');
        $result = Db::name('zixun')->where('id',$id)->delete();
        if($result>0){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 搜索留言
     */
    public function liuyansearchs(){
        $starttime = input('start_time');
        $endtime = input('end_time');
        $keyword = input('keyword');
        if(!empty($starttime)&&empty($endtime)){
            $this->error('请选择结束时间');
        }
        if(empty($starttime)&&!empty($endtime)){
            $this->error('请选择开始时间');
        }
        $sql = Db::name('zixun')->alias('z')->join('edu_userinfo u','z.userid = u.id')->where('z.deltime','0')->order('z.id desc')->field('z.id,u.xingming as name,z.content,z.recontent,z.dottime,z.redottime');
        if(!empty($starttime)&&!empty($endtime)){
            $sql = $sql->where('z.dottime','>=',strtotime($starttime))->where('z.dottime','<=',strtotime($endtime));
        }
        if(!empty($keyword)){
            $sql = $sql->where('u.xingming','like','%'.trim($keyword).'%');
        }
        $result = $sql->paginate(8);
        $page = $result->render();
        $this->assign('res',$result);
        $this->assign('page',$page);
        return $this->fetch('liuyan');
    }

    /**
     * 老师可预约的时间
     */
    public function teahyuyue(){
        $userid = input('userid');
       
        $result = Db::name('teachyuyue')->where('userid',$userid)->find();
       
        $this->assign('res',$result);
        $this->assign('page',$result);
        return $this->fetch('teachyuyue');
    }
  /**
     * logo
     */
    public function logo(){
        $result= Db::name('logo')->where('id',1)->find();

        if(!empty($result)){
            $this->assign('image',$result['log']);
            $result['log'] = 'http://'.$_SERVER['HTTP_HOST'].'/upload/'.$result['log'];
            $this->assign('res',$result);

        }else{
            $this->assign('res',array('id'=>'','log'=>'__TMPL__/public/assets/images/default-thumbnail.png'));
            $this->assign('image','');
        }
        return $this->fetch('log');
    }
    /**
     * 设置logo
     */
    public function addlogo(){
        $id = input('id');
        $logo = input('logo.thumbnail');
        $datas['log'] = $logo;
        $datas['dottime'] = time();
        if(empty($id)){
            $result= Db::name('logo')->insert($datas);
        }else{
            $result= Db::name('logo')->where('id',$id)->update($datas);
        }
        if($result>0){
            $this->success('提交成功');
        }else{
            $this->error('提交失败');
        }

    }
}